package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2024-02-20
 * Time: 15:52
 */
public class ReturnOperation implements IOperation{
    @Override  //接口重写
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("请输入要归还图书的书名: ");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currenSize = bookList.getUsedSize(); //得到书架的图书数量
        for (int i = 0; i < currenSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                //有这本书
                book.setBorrowed(false);
                System.out.println("归还成功! ");
                return;
            }
        }
        System.out.println("没有你要归还的书:"+name);
    }

}
